<style type="text/css">
.loader {
		position: absolute;
		width: 100%;
		height: 100%;
		transform: rotate(165deg);
		animation: rotate 2s infinite;
	}

	@keyframes rotate {
		0% {
			transform: rotate(0deg);
		}
		100% {
			transform: rotate(360deg);
		}
	}

	.loader::before,
	.loader::after {
		content: '';
		position: absolute;
		top: 50%;
		left: 50%;
		display: block;
		width: 20em;
		height: 20em;
		border-radius: 2.5em;
		transform: translate(-50%, -50%);
	}

	.loader::before {
		animation: before 2s infinite;
	}

	@keyframes before {
		0% {
			width: 0.5em;
			box-shadow: 1em -0.5em 0.5em rgba(100, 156, 136, 0.75), -1em 0.5em 0.5em rgba(150, 120, 20, 0.75);
		}
		55% {
			width: 2.5em;
			box-shadow: 0 -0.5em rgba(100, 156, 136, 0.75), 0 0.5em rgba(150, 120, 20, 0.75);
		}
		70% {
			width: 0.5em;
			box-shadow: -1em -0.5em rgba(100, 156, 136, 0.75), 1em 0.5em rgba(150, 120, 20, 0.75);
		}
		100% {
			box-shadow: 1em -0.5em rgba(100, 156, 136, 0.75), -1em 0.5em rgba(150, 120, 20, 0.75);
		}
	}

	.loader::after {
		animation: after 2s infinite;
	}

	@keyframes after {
		0% {
			height: 0.5em;
			box-shadow: -0.5em -1em 0.5em rgba(200, 56, 36, 0.75), 0.5em 1em 0.5em rgba(50, 60, 80, 0.75);
		}
		55% {
			height: 2.5em;
			box-shadow: -0.5em 0 rgba(200, 56, 36, 0.75), 0.5em 0 rgba(50, 60, 80, 0.75);
		}
		70% {
			height: 0.5em;
			box-shadow: -0.5em 1em rgba(200, 56, 36, 0.75), 0.5em -1em rgba(50, 60, 80, 0.75);
		}
		100% {
			box-shadow: -0.5em -1em rgba(200, 56, 36, 0.75), 0.5em 1em rgba(50, 60, 80, 0.75);
		}
	}
}
</style>
<style type="text/css">
	.zeroPadding {
		padding: 0;
	}

	.myBorder {
		border: 1px solid #ccc;
	}

	.goodsType{
		width: 100%;
		text-align: center;
		background: #605CA8;
		color: white;
		margin-top: 5px;
		margin-bottom: 5px;
	}
</style>

<div id="loading" style="position: absolute;width:100%;height:100%;background-color: rgba(0, 0, 0, 0.5);z-index: 999999;display: none;">
	<div class="loader" style="z-index: 999999;">

	</div>
</div>

<div class="box box-primary">
	<div class="box-header with-border">
		<h3 class="box-title">商品清单</h3>
	</div>
	<!-- /.box-header -->
	<!-- form start -->
	<form role="form" onkeydown="if(event.keyCode==13)return false;">
		<div class="box-body">
			<div class="form-group" style="width: 100%;margin-bottom: 20px;">
				<label for="muCode">会&nbsp;&nbsp;员&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
				<select id="muCode" class="form-control muCode" style="width: 20%;margin-left: 5px;">
					<option value=""></option>
					@foreach ($muList as $member)
					<option value="{{$member->muCode}}">{{$member->muNickName}} | {{$member->muMobile}}</option>
					@endforeach
				</select>

				<!--<button id="btnSaleType" type="button" class="btn bg-purple margin" style="margin-left: 50px;">卡项销售</button>-->

				<a href='./../member/create?back=storegoodsout' class="btn bg-olive margin" style="margin-left: 50px;">添加会员</a>

			</div>

            <div class="form-group" style="width: 100%;margin-bottom: 20px;">
            	<label for="beautician" style="display: inline;">销售&nbsp;&nbsp;</label>
            	<select id="beautician" class="form-control muCode" style="width: 20%;display: inline;margin-left: 5px;">
            		<option value=""></option>
            		@foreach ($bcList as $beautician)
            		<option value="{{$beautician->auCode}}">{{$beautician->name}}</option>
            		@endforeach
            	</select>
            </div>

			<div id="" class="col-sm-6">
				<div class="row">
					<div class="col-sm-4" style="text-align: center;"><strong>商品名称</strong></div>
					<div class="col-sm-2" style="text-align: center;"><strong>原价</strong></div>
					<div class="col-sm-2" style="text-align: center;"><strong>会员价</strong></div>
					<div class="col-sm-2" style="text-align: center;"><strong>数量</strong></div>
					<div class="col-sm-2" style="text-align: center;"><strong>小计</strong></div>
				</div>
			</div>
			<div id="" class="col-sm-6">
				<div class="row">
					<div class="col-sm-4" style="text-align: center;"><strong>商品名称</strong></div>
					<div class="col-sm-2" style="text-align: center;"><strong>原价</strong></div>
					<div class="col-sm-2" style="text-align: center;"><strong>会员价</strong></div>
					<div class="col-sm-2" style="text-align: center;"><strong>数量</strong></div>
					<div class="col-sm-2" style="text-align: center;"><strong>小计</strong></div>
				</div>
			</div>

			<div id="typeSingle" class="col-sm-12 goodsType">
				<label class="">单品</label>
			</div>

			@foreach ($sgList as $sgInfo)
				@if ($sgInfo->sgChildNum <= 1 && $sgInfo->sgIsTimeCard == 0)
				<div id="" class="col-sm-6 typeSingle">
					<div id="div{{$sgInfo->sgId}}" class="row">
						<button id="name{{$sgInfo->sgId}}" type="button" class="btn btn-primary col-sm-4 sgName" style="33.3333%">{{$sgInfo->sgName}}</button>
						<label class="form-control col-sm-2" style="width: 16.6666%;border: 0px;text-align: center;">{{$sgInfo->sgPrice}}</label>
						<input id="price{{$sgInfo->sgId}}" type="text" class="form-control col-sm-2 sgSalePrice" style="width: 16.6666%" value="{{$sgInfo->sgPrice}}">
						<div class="input-group col-sm-4" style="width: 16.6666%;float: left;">
							<input id="num{{$sgInfo->sgId}}" type="text" class="form-control sgSaleNum" value="0">
							<span id="reset{{$sgInfo->sgId}}" class="btn input-group-addon resetSaleNum numReset"><i class="fa fa-close" style="color: #FF4040"></i></span>
						</div>
						<label id="total{{$sgInfo->sgId}}" class="form-control col-sm-2 itemTotalPay" style="width: 16.6666%;border: 0px;text-align: center;">0</label>
						<input id="minPrice{{$sgInfo->sgId}}" type="hidden" value="{{$sgInfo->sgPrice}}" />
						<input id="shouldPrice{{$sgInfo->sgId}}" type="hidden" value="{{$sgInfo->sgPrice}}" />
						<input id="typeSign{{$sgInfo->sgId}}" type="hidden" value="single" />
					</div>
				</div>
				@endif
			@endforeach

			<div id="typeCombo" class="col-sm-12 goodsType" style="width: 100%;">
				<label class="">套餐</label>
			</div>

			@foreach ($sgList as $sgInfo)
				@if ($sgInfo->sgChildNum > 1 && $sgInfo->sgIsTimeCard == 0)
				<div id="" class="col-sm-6 typeCombo">
					<div id="div{{$sgInfo->sgId}}" class="row">
						<button id="name{{$sgInfo->sgId}}" type="button" class="btn btn-primary col-sm-4 sgName" style="33.3333%">{{$sgInfo->sgName}}</button>
						<label class="form-control col-sm-2" style="width: 16.6666%;border: 0px;text-align: center;">{{$sgInfo->sgPrice}}</label>
						<input id="price{{$sgInfo->sgId}}" type="text" class="form-control col-sm-2 sgSalePrice" style="width: 16.6666%" value="{{$sgInfo->sgPrice}}">
						<div class="input-group col-sm-4" style="width: 16.6666%;float: left;">
							<input id="num{{$sgInfo->sgId}}" type="text" class="form-control sgSaleNum" value="0">
							<span id="reset{{$sgInfo->sgId}}" class="btn input-group-addon resetSaleNum numReset"><i class="fa fa-close" style="color: #FF4040"></i></span>
						</div>
						<label id="total{{$sgInfo->sgId}}" class="form-control col-sm-2 itemTotalPay" style="width: 16.6666%;border: 0px;text-align: center;">0</label>
						<input id="minPrice{{$sgInfo->sgId}}" type="hidden" value="{{$sgInfo->sgPrice}}" />
						<input id="shouldPrice{{$sgInfo->sgId}}" type="hidden" value="{{$sgInfo->sgPrice}}" />
						<input id="typeSign{{$sgInfo->sgId}}" type="hidden" value="combo" />
					</div>
				</div>
				@endif
			@endforeach

			<div id="typeCard" class="col-sm-12 goodsType" style="width: 100%;">
				<label class="">卡项</label>
			</div>

			@foreach ($sgList as $sgInfo)
				@if ($sgInfo->sgIsTimeCard == 1)
				<div id="" class="col-sm-6 typeCard">
					<div id="div{{$sgInfo->sgId}}" class="row">
						<button id="name{{$sgInfo->sgId}}" type="button" class="btn btn-primary col-sm-4 sgName" style="33.3333%">{{$sgInfo->sgName}}</button>
						<label class="form-control col-sm-2" style="width: 16.6666%;border: 0px;text-align: center;">{{$sgInfo->sgPrice}}</label>
						<input id="price{{$sgInfo->sgId}}" type="text" class="form-control col-sm-2 sgSalePrice" style="width: 16.6666%" value="{{$sgInfo->sgPrice}}">
						<div class="input-group col-sm-4" style="width: 16.6666%;float: left;">
							<input id="num{{$sgInfo->sgId}}" type="text" class="form-control sgSaleNum" value="0">
							<span id="reset{{$sgInfo->sgId}}" class="btn input-group-addon resetSaleNum numReset"><i class="fa fa-close" style="color: #FF4040"></i></span>
						</div>
						<label id="total{{$sgInfo->sgId}}" class="form-control col-sm-2 itemTotalPay" style="width: 16.6666%;border: 0px;text-align: center;">0</label>
						<input id="minPrice{{$sgInfo->sgId}}" type="hidden" value="{{$sgInfo->sgPrice}}" />
						<input id="shouldPrice{{$sgInfo->sgId}}" type="hidden" value="{{$sgInfo->sgPrice}}" />
						<input id="typeSign{{$sgInfo->sgId}}" type="hidden" value="card" />
					</div>
				</div>
				@endif
			@endforeach

			<div class="row" style="margin-bottom: 20px;">
				<div class="col-md-2 col-md-offset-10">总共需支付：<strong id="totalPay" style="color: red;">0</strong></div>
			</div>

			<div id="divMemberMoney" class="form-group" style="width: 50%;margin-bottom: 20px;display: none;">
				<label for="muCode col-sm-2">会员卡余额:</label>
				<label for="muCode col-sm-4"><strong id="memberMoney" style="color: #FF7F00;font-size: 20px;">0</strong></label>
			</div>



			<!--<div id="divPayWay" class="form-group col-sm-12" style="margin-bottom: 20px;">
				<label for="payWay" class=" control-label">支付方式</label>
				<div class="">
					<input type="hidden" name="payWay" />
					<select id="payWay" class="form-control payWay" name="payWay" data-value="">
						<option value=""></option>
						<option value="现金">现金</option>
						<option value="支付宝">支付宝</option>
						<option value="微信">微信</option>
					</select>
				</div>
			</div>-->

			<div id="divCardPay" class="form-group" style="display: none;">
			    <label for="sgIsIncludeService" class="col-sm-2  control-label">是否用会员卡结算</label>
			    <input style="margin-right: 5px;" name="cardPay" type="checkbox">
                <input id='hideCardPay' type="hidden" value="0">
			</div>

            <div id="divIsFirstPay" class="form-group">
                <label for="isFirstPay" class="col-sm-2  control-label">是否首次购买</label>
                <input style="margin-right: 5px;" name="isFirstPay" type="checkbox" checked="checked">
                <input id='hideFirstPay' type="hidden" value="1">
            </div>

			<div id="divPayWay" class="form-group col-sm-12">
				<label for="payWay col-sm-2 ">&nbsp;支付方式&nbsp;&nbsp;</label>
					<select id="payWay" class="muCode col-sm-3">
						<option value=""></option>
                        @foreach (config('ami.payWay') as $payWay)
                        <option value="{{$payWay}}">{{$payWay}}</option>
                        @endforeach
					</select>
			</div>

			<div class="form-group col-sm-12">
				<label for="memo" class="control-label" style="float: left;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;备注&nbsp;&nbsp;&nbsp;&nbsp;</label>
					<div class="input-group col-sm-6"  style="float: left;">
						<span class="input-group-addon"><i class="fa fa-pencil fa-fw"></i></span>
						<input type="text" id="memo" name="memo" value="" class="form-control sName" placeholder="输入 备注">
					</div>
			</div>

			<div id="" class="row col-sm-10" style="margin-top: 20px;">
				<div class="box-footer">
					<button type="" class="btn btn-default" style="margin-left: 200px;">返回</button>
					<div type="" onclick="submit()" class="btn btn-info pull-right">提交</div>
				</div>
			</div>
		</div>
	</form>
</div>

<script type="text/javascript">

	$('#typeSingle').click(function(){

		$(".sgSaleNum").val('0');
		$(".sgName").removeClass("btn-warning");
		$(".sgName").addClass("btn-primary");
		$('.typeSingle').show();
		$('.typeCombo').hide();
		$('.typeCard').hide();
		countPay();
	});

	$('#typeCombo').click(function(){

		$(".sgSaleNum").val('0');
		$(".sgName").removeClass("btn-warning");
		$(".sgName").addClass("btn-primary");
		$('.typeSingle').hide();
		$('.typeCombo').show();
		$('.typeCard').hide();
		countPay();

	});

	$('#typeCard').click(function(){

		$(".sgSaleNum").val('0');
		$(".sgName").removeClass("btn-warning");
		$(".sgName").addClass("btn-primary");
		$('.typeSingle').hide();
		$('.typeCombo').hide();
		$('.typeCard').show();
		countPay();

	});

	$('.typeCombo').hide();
	$('.typeCard').hide();


	$(function () {
        $("#muCode").select2({"allowClear":true,"placeholder":{"id":"","text":"\u8bf7\u9009\u62e9\u4f1a\u5458"}});
        $("#payWay").select2({"allowClear":true,"placeholder":{"id":"","text":"请选择支付方式"}});
        $("#beautician").select2({"allowClear":true,"placeholder":{"id":"","text":"服务的美容师"}});

        $('[name="cardPay"]').bootstrapSwitch({    //初始化按钮
	       onText:"是",
	       offText:"否",
	       onColor:"success",
	       offColor:"info",
	       size:"small",
	       onSwitchChange:function(event,state){
                $('#hideCardPay').val(state?'1':'0');
	       },
	    });

        $('[name="isFirstPay"]').bootstrapSwitch({    //初始化按钮
           onText:"是",
           offText:"否",
           onColor:"success",
           offColor:"info",
           size:"small",
           onSwitchChange:function(event,state){
               $('#hideFirstPay').val(state?'1':'0');
           },
        });
    });

	$('#muCode').change(function(){
		var muCode = $(this).children('option:selected').val();

		$('#loading').show();
		$.get("{{route('getGoodsPrice')}}?sId={{$sId}}&muCode="+muCode, function(result){
			$('#loading').hide();
			console.log(result);
			if (typeof(result) == "string"){
				result = JSON.parse(result);
			}
		    var infoList = result.data;
		    for(var i=0;i<$('.sgSalePrice').length;i++){
		    	var sgId = $('.sgSalePrice')[i].id.replace("price", "");
		    	for (var j=0;j<infoList.length;j++){
		    		if (sgId == infoList[j].goodsId){
		    			$($('.sgSalePrice')[i]).val(infoList[j].goodsPrice);
		    			$('#shouldPrice'+sgId).val(infoList[j].goodsPrice);
		    			$('#minPrice'+sgId).val(infoList[j].goodsMinPrice);
		    		}
		    	}
			}

			countPay();
		});

		// 获取会员卡余额
	    var moneyUrl = "{{ route('getAccountMoney') }}?sId={{$sId}}&userCode="+muCode;
	    $.get(moneyUrl, function (data) {
	    	data =JSON.parse(data);
	    	if (data.code == 0){
	    		toastr.warning(data.msg);
	    		return;
	    	}
	    	console.log(data);
	    	$('#memberMoney').html(data.data)
	    	if (data.data == 0){
	    		$('#divMemberMoney').hide();
	    	} else {
	    		$('#divMemberMoney').show();

	    	}
	    	var accountMoney = data.data;
	    	var totalPay = $('#totalPay').html();

	    	if (Number(accountMoney) > 0){
	    		$("#divCardPay").show();
	    	}else{
	    		$("#divCardPay").hide();
	    		$('#hideCardPay').val('0');
	    	}

//	    	if (Number(accountMoney) > 0){
//	    		$("#payWay").append("<option value='会员卡'>会员卡</option>");
//	    	}else{
//	    		$("#payWay option[value='会员卡']").remove(); //删除Select中Value='3'的Optiona
//	    	}
//	    	$("#payWay").select2({"allowClear":true,"placeholder":{"id":"","text":"请选择支付方式"}});

//	    	if (Number(accountMoney) < Number(totalPay)){
//				$('#divPayWay').show();
//			}else{
//				$('#divPayWay').hide();
//			}

			countPay();
	    });

        // 判断是否第一次到店
        $.ajax({
          type: 'POST',
          url: "{{route('isFirstBuy')}}",
          data: {
              sId: {{$sId}},
              muCode: muCode,
          },
          success: function(data){
          	console.log(data)

          	if (typeof(data) == "string"){
          		data = JSON.parse(data);
          		if (data.code == 1){
                    if (data.data == 1){
                        $('#divIsFirstPay').show();
                    }else{
                        $('#divIsFirstPay').hide();
                        $('#hideFirstPay').val('0');
                    }
          		}else{
          			toastr.warning(data.msg);
          		}
          	}
          },
          error:function(xhr,state,errorThrown){
          	$('#loading').hide();
          	toastr.warning('获取信息失败，请联系管理员');
        	console.log(xhr);
        	console.log(state);
        	console.log(errorThrown);
          }
        });
	})

	$('#btnSaleType').click(function(){
		$(".sgSaleNum").val('0');
		$(".sgName").removeClass("btn-warning");
		$(".sgName").addClass("btn-primary");
		if ($('#btnSaleType').html() == '卡项销售'){
			$('.typeCards').show();
			$('.typeGoods').hide();
			$('#btnSaleType').html('商品销售');
		}else{
			$('.typeGoods').show();
			$('.typeCards').hide();
			$('#btnSaleType').html('卡项销售');
		}
		countPay();
	});

	//$('.typeCards').hide();

	$('.sgName').click(function(){
		var sgId = this.id.replace("name", "");
		var sgNum = $('#num'+sgId).val();
		if (sgNum == ""){
			sgNum = 0;
			$('#num'+sgId).val('0');
		}

		if (Number($('#price'+sgId).val()) < Number($('#minPrice'+sgId).val()) && $('#typeSign'+ sgId).val() != "card"){
			toastr.warning('最低价格为：'+$('#minPrice'+sgId).val());
			numResetClick(sgId);
			return;
		}

		$('#num'+sgId).val(parseInt(sgNum) + 1);
		var temp = ((parseInt(sgNum) + 1)*$('#price'+sgId).val()).toFixed(2);
		temp = temp==parseInt(temp)?parseInt(temp):temp;
		console.log('total sgName:' + temp);
		$('#total'+sgId).html(temp);
		$('#'+this.id).removeClass("btn-primary");
		$('#'+this.id).addClass("btn-warning");
		countPay();
	});

	$('.numReset').click(function(){
		var sgId = this.id.replace("reset", "");
		if($(this).val() == ""){
            $(this).val(0);
		}

		numResetClick(sgId);
	});

	function numResetClick(sgId){
		$('#num'+sgId).val('0');
		$('#total'+sgId).html(0);
		$('#name'+sgId).removeClass("btn-warning");
		$('#name'+sgId).addClass("btn-primary");
		countPay();
	}

	$('.sgSalePrice').bind('input propertychange', function(){
		var sgId = this.id.replace("price", "");
		console.log(sgId)
		if($(this).val() == ""){
            $(this).val(0);
		}

		if (Number($('#price'+sgId).val()) < Number($('#minPrice'+sgId).val()) && $('#typeSign'+ sgId).val() != "card"){
			toastr.warning('最低价格为：'+$('#minPrice'+sgId).val());
			numResetClick(sgId);
			return;
		}

		var sgNum = $('#num'+sgId).val();
		var temp = (parseInt(sgNum)*$(this).val()).toFixed(2);
		temp = temp==parseInt(temp)?parseInt(temp):temp;
		console.log('total sgSalePrice:' + temp);
		$('#total'+sgId).html(temp);
		countPay();
	})

	$('.sgSaleNum').bind('input propertychange', function(){
		var sgId = this.id.replace("num", "");
		console.log(sgId)

		if($(this).val() == ""){
            $(this).val(0);
		}

		if (Number($(this).val()) == 0){
			$('#name'+sgId).removeClass("btn-warning");
			$('#name'+sgId).addClass("btn-primary");
		}else if (Number($(this).val()) > 0){
			$('#name'+sgId).removeClass("btn-primary");
			$('#name'+sgId).addClass("btn-warning");
		}

		var sgNum = $(this).val();
		var sgSalePrice = $('#price'+sgId).val()
		var temp = (Number(sgSalePrice)*Number($(this).val())).toFixed(2);
		temp = temp==parseInt(temp)?parseInt(temp):temp;
		console.log('total sgSaleNum:' + temp);
		$('#total'+sgId).html(temp);
		countPay();
	})

	function countPay(){
		var totalPay = 0;
		for(var i=0;i<$('.itemTotalPay').length;i++){
			var sgId = $('.itemTotalPay')[i].id.replace('total', '');
			var sgNum = $('#num'+sgId).val();
			var sgSalePrice = $('#price'+sgId).val();
			var itemPrice = (sgNum*sgSalePrice).toFixed(2);
			itemPrice = itemPrice == parseInt(itemPrice)?parseInt(itemPrice):itemPrice;
			$($('.itemTotalPay')[i]).html(itemPrice);
			var thisPay = $($('.itemTotalPay')[i]).html();
			thisPay = Number(thisPay);
			totalPay += thisPay;
		}

		totalPay = Number(totalPay).toFixed(2)
		totalPay = totalPay==parseInt(totalPay)?parseInt(totalPay):totalPay;
		console.log('totalPay html:' + totalPay)
		$('#totalPay').html(totalPay);

		var accountMoney = $('#memberMoney').html();;
    	var totalPay = $('#totalPay').html();
    	console.log("accountMoney:" + Number(accountMoney));
    	console.log("totalPay:" + Number(totalPay));

    	var saleTotalNum = 0;
		for (var i=0;i<$(".sgSaleNum").length;i++){
			if ($(".sgSaleNum")[i].value > 0){
				saleTotalNum = saleTotalNum + parseInt($(".sgSaleNum")[i].value);
			}
		}
		if (saleTotalNum == 0){
			$('#divPayWay').hide();
		}else{
			$('#divPayWay').show();
		}
//  	if (Number(accountMoney) < Number(totalPay)){
//			$('#divPayWay').show();
//		}else{
//			$('#divPayWay').hide();
//		}
	}

	function submit(){

		var totalPay = $('#totalPay').html();
//		if (Number(totalPay) == 0){
//			toastr.warning('请选择要售出的商品');
//			return;
//		}
		var saleTotalNum = 0;
		for (var i=0;i<$(".sgSaleNum").length;i++){
			if ($(".sgSaleNum")[i].value > 0){
				saleTotalNum = saleTotalNum + parseInt($(".sgSaleNum")[i].value);
			}
		}
		if (saleTotalNum == 0){
			toastr.warning('请选择要售出的商品');
			return;
		}
		console.log('saleTotalNum:' + saleTotalNum);

		var sId = {{$sId}};
		var muCode = $('#muCode').val();
		var sgId = "";
		var sgoMemo = $('#memo').val();
		var sgoSaleNum = "";
		var sgoSalePrice = "";
		var createUser = "{{$createUser}}";
		var sgoPayWay = $('#payWay').val();
		var isCustomPrice = "";
		var accountMoney = $('#memberMoney').html();
		var totalPay = $('#totalPay').html();
		var cardPay = $('#hideCardPay').val();
        var firstBuy = $('#hideFirstPay').val();
        var beauticianId = $('#beautician').val();
		if (cardPay == true && Number(accountMoney) < Number(totalPay) && sgoPayWay == ""){
			toastr.warning('请选择支付方式');
			return;
		}

		if (cardPay == false && sgoPayWay == ""){
			toastr.warning('请选择支付方式');
			return;
		}

		var useIndex = 0;
		var useMemo = sgoMemo;

		for (var i=0;i<$(".sgSaleNum").length;i++){

			if ($(".sgSaleNum")[i].value == 0){
				continue;
			}

			var thisSgId = $('.sgSaleNum')[i].id.replace("num", "");
			var thisPay = $('#total'+thisSgId).html();
			var thisSaleNum = $('#num'+thisSgId).val();
			thisPay = Number(thisPay);


			sgId +=  '|' + thisSgId;
			sgoSaleNum += '|' + thisSaleNum;
			sgoSalePrice += '|' + thisPay;
			if ($('#price'+thisSgId).val() != $('#shouldPrice'+thisSgId).val()){
				isCustomPrice += "|" + 1;
			}else{
				isCustomPrice += "|" + 0;
			}
			if (useIndex > 0){
				sgoMemo = sgoMemo + "|" + useMemo
			}
			useIndex++;
		}

		sgId = sgId.substring(1);
		sgoSaleNum = sgoSaleNum.substring(1);
		sgoSalePrice = sgoSalePrice.substring(1);
		isCustomPrice = isCustomPrice.substring(1);

		var sellData = {};
		sellData.sId = sId;
		sellData.muCode = muCode;
		sellData.sgId = sgId;
		sellData.sgoSaleNum = sgoSaleNum;
		sellData.sgoSalePrice = sgoSalePrice;
		sellData.createUser = createUser;
		sellData.sgoPayWay = sgoPayWay;
		sellData.isCustomPrice = isCustomPrice;
		sellData.accountPay = accountMoney;
		sellData.sgoMemo = sgoMemo;
		sellData.cardPay = cardPay;
        sellData.beauticianId = beauticianId;
        sellData.firstBuy = firstBuy;
		console.log(sellData);
//		toastr.success('666');
//		return;
		$('#loading').show();
		$.ajax({
		  type: 'POST',
		  url: "{{route('sellGoods')}}",
		  data: sellData,
		  success: function(data){
		  	console.log(data)
		  	$('#loading').hide();
		  	if (typeof(data) == "string"){
		  		data = JSON.parse(data);
		  		if (data.code == 1){
		  			toastr.success('提交成功');
		  			setTimeout(function(){
	                    window.history.back();
	                }, 800);
		  		}else{
		  			toastr.warning(data.msg);
		  		}
		  	}
		  },
		  error:function(xhr,state,errorThrown){
		  	$('#loading').hide();
		  	toastr.warning('提交失败，请联系管理员');
			console.log(xhr);
			console.log(state);
			console.log(errorThrown);
		  }
		});
	}

</script>
